﻿namespace Furesoft.Styling.Winforms
{
    using System;
    using System.ComponentModel;
    using System.Drawing;
    using System.Drawing.Design;
    using System.Windows.Forms;
    using Furesoft.Styling.Design.Definition;
    using Furesoft.Styling.Design.Style;
    using Furesoft.Styling.Transitions;

    public class StylableForm : Form, IStylableControl
    {
        [Editor(typeof(StyleStringEditor), typeof(UITypeEditor))]
        [Category("Style")]
        public string Style { get; set; }

        [Editor(typeof(DefinitionStringEditor), typeof(UITypeEditor))]
        [Category("Style")]
        public string Definition { get; set; }

        public Transition Transition { get; set; }

        public string Class { get; set; }

        public RegionShape Shape { get; set; }

        public Region Corner { get; set; }

        public StylableForm()
        {
            StyleChanger.Init(this.Controls, this);

            this.Load += (sender, e) =>
            {
                Controls.Clear();

                if (Definition != null)
                {
                    foreach (Control item in DefinitionReader.Read(Definition).Controls)
                    {
                        Controls.Add(item);
                    }
                }

                this.Apply();
            };
        }

        public void Apply()
        {
            StyleChanger.Execute(this.Style);
        }

        public void Reset()
        {
            StyleChanger.Reset();
        }
    }
}